﻿// ———————————————————————–
// <copyright file="ResourceUCADStatusCode.cs" company="The MITRE Corporation">
//    Copyright (c) 2014 The MITRE Corporation. All rights reserved.
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//    http://www.apache.org/licenses/LICENSE-2.0
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
// </copyright>
// ———————————————————————–
/////////////////////////////////////////////////////////////////////////////////////////////////
// ResourceUCADStatusCode.cs:
// Unit statuses based off of recommendations from UCAD.
// Project: IC.NET - EDXL Library
//
// Language:    C#, .NET 4.0
// Platform:    Windows 7, VS 2012
// Author:      Jim Cronin MITRE Bedford

/////////////////////////////////////////////////////////////////////////////////////////////////

// Copyright (c) 2014 The MITRE Corporation. All rights reserved.
//
// NOTICE
// This software was produced for the U. S. Government
// under Contract No. FA8721-09-C-0001, and is
// subject to the Rights in Noncommercial Computer Software
// and Noncommercial Computer Software Documentation Clause
// (DFARS) 252.227-7014 (JUN 1995)

using System;

namespace EDXLSharp.NIEMCADLib
{
  /// <summary>
  /// Unit statuses based off of recommendations from UCAD.
  /// </summary>
  public enum ResourceUCADStatusCode
  {
    /// <summary>
    /// Assigned to an incident.
    /// </summary>
    Assigned,
    /// <summary>
    /// Enroute to an incident.
    /// </summary>
    Enroute,
    /// <summary>
    /// At an incident.
    /// </summary>
    AtScene,
    /// <summary>
    /// Transporting patient (or other) to a destination such as a hospital.
    /// </summary>
    Transport,
    /// <summary>
    /// Completed transport.
    /// </summary>
    TransportComplete,
    /// <summary>
    /// Completed transport. Leaving destination of transport.
    /// </summary>
    Cleared,
    /// <summary>
    /// Assigned to a designated stand-by location either predetermined or dynamic and based on incident activity and better readiness for response.
    /// </summary>
    AssignedToPost,
    /// <summary>
    /// Enroute to a designated stand-by location either predetermined or dynamic and based on incident activity and better readiness for response.
    /// </summary>
    EnrouteToPost,
    /// <summary>
    /// At a designated stand-by location either predetermined or dynamic and based on incident activity and better readiness for response.
    /// </summary>
    AtPost,
    /// <summary>
    /// Available in the area of a designated stand-by location either predetermined or dynamic and based on incident activity and better readiness for response. 
    /// </summary>
    AvailableInAreaOfAssignedPost,
    /// <summary>
    /// A resource is available onfor for emergency incidents, for example, a unit has released the patient and can respond, but is working on paperwork, stocking supplies.
    /// </summary>
    AvailableForEmergencyIncidentsOnly,
    /// <summary>
    /// In the area of the incident and waiting for approval to proceed to the scene of the incident.
    /// </summary>
    Staged,
    /// <summary>
    /// A secondary on scene time that tracks when stand-by stops and contact is made on the incident.
    /// </summary>
    PatientOrIncidentContact
  }

  public static class ResourceUCADStatusCodeHelper
  {
    /// <summary>
    /// Gets the text to be written to XML for this status code
    /// </summary>
    /// <param name="code"></param>
    /// <returns></returns>
    public static string GetText(this ResourceUCADStatusCode code)
    {
      switch (code)
      {
        case ResourceUCADStatusCode.Assigned:
          return "ASSIGNED";
        case ResourceUCADStatusCode.Enroute:
          return "ENROUTE";
        case ResourceUCADStatusCode.AtScene:
          return "AT SCENE";
        case ResourceUCADStatusCode.Transport:
          return "TRANSPORT";
        case ResourceUCADStatusCode.TransportComplete:
          return "TRANSPORT COMPLETE";
        case ResourceUCADStatusCode.Cleared:
          return "CLEARED";
        case ResourceUCADStatusCode.AssignedToPost:
          return "ASSIGNED TO POST";
        case ResourceUCADStatusCode.EnrouteToPost:
          return "ENROUTE TO POST";
        case ResourceUCADStatusCode.AtPost:
          return "AT POST";
        case ResourceUCADStatusCode.AvailableInAreaOfAssignedPost:
          return "AVAILABLE IN AREA OF ASSIGNED POST";
        case ResourceUCADStatusCode.AvailableForEmergencyIncidentsOnly:
          return "AVAILABLE FOR EMERGENCY INCIDENTS ONLY";
        case ResourceUCADStatusCode.Staged:
          return "STAGED";
        case ResourceUCADStatusCode.PatientOrIncidentContact:
          return "PATIENT/INCIDENT CONTACT";
        default:
          throw new ArgumentOutOfRangeException("Not a valid/known value for ResourceUCADStatusCode");
      }
    }

    /// <summary>
    /// Converts a text value to a ResourcePrimaryStatusCode
    ///  - First checks for the XML text of each code
    ///  - Lastly just calls Enum.Parse
    /// </summary>
    /// <param name="value">String to parse</param>
    /// <returns>ResourcePrimaryStatusCode described by value</returns>
    /// <exception cref="System.ArgumentNullException">Thrown if value is null</exception>
    /// <exception cref="System.ArgumentException">Thrown if value is empty or whitespace</exception>
    /// <exception cref="System.OverflowException">Thrown if value does not represent a ResourcePrimaryStatusCode</exception>
    public static ResourceUCADStatusCode GetCode(string value)
    {
      switch (value)
      {
        case "ASSIGNED":
          return ResourceUCADStatusCode.Assigned;
        case "ENROUTE":
          return ResourceUCADStatusCode.Enroute;
        case "AT SCENE":
          return ResourceUCADStatusCode.AtScene;
        case "TRANSPORT":
          return ResourceUCADStatusCode.Transport;
        case "TRANSPORT COMPLETE":
          return ResourceUCADStatusCode.TransportComplete;
        case "CLEARED":
          return ResourceUCADStatusCode.Cleared;
        case "ASSIGNED TO POST":
          return ResourceUCADStatusCode.AssignedToPost;
        case "ENROUTE TO POST":
          return ResourceUCADStatusCode.EnrouteToPost;
        case "AT POST":
          return ResourceUCADStatusCode.AtPost;
        case "AVAILABLE IN AREA OF ASSIGNED POST":
          return ResourceUCADStatusCode.AvailableInAreaOfAssignedPost;
        case "AVAILABLE FOR EMERGENCY INCIDENTS ONLY":
          return ResourceUCADStatusCode.AvailableForEmergencyIncidentsOnly;
        case "STAGED":
          return ResourceUCADStatusCode.Staged;
        case "PATIENT/INCIDENT CONTACT":
          return ResourceUCADStatusCode.PatientOrIncidentContact;
        default:
          return (ResourceUCADStatusCode)Enum.Parse(typeof(ResourceUCADStatusCode), value);
      }
    }
  }
}
